<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>

  <body>
    <button onclick="myFunc()">加载bilibili</button>
    <script>
      //获取当前页面URL
      var x = location.href;
      document.write("<br>" + x + "<br>");
      //获取主机名
      x = location.hostname;
      document.write(x + "<br>");
      //获取当前页面路径点
      x = location.pathname;
      document.write(x + "<br>");
      //查看当前页面协议
      x = location.protocol;
      document.write(x + "<br>");
      //获取端口号
      x = location.port;
      document.write(x + "<br>");
      //窗口位置分配
      function myFunc() {
        location.assign("https://bilibili.com/");
      }
    </script>
  </body>
</html>
